<?php


namespace Admin\Model;

use Think\Model;

class PhManagerModel extends Model{
    protected $tableName = "hospital_type";
    public function add_hospital_type($data){
        return $this->add($data);
    }
    public function add_hospital_group($data){
        return M('hospital_special_group')->add($data);
    }
    public function get_hospital_type($data){
        $hid = $data['hid'];
        $res = $this->where("hid=' $hid'")->select();
        $i =0;
        foreach($res as $some){
            $specialGroup = array();
            $group = explode(",",$some['special_group']);
            foreach ($group as $item) {
                $special = M('hospital_special_group')->where("id=' $item'")->select();
                array_push($specialGroup,$special[0]);
            }
            $res[$i]['special'] = $specialGroup;
            $i++;
        }
        return  $res;
    }
    public function lists(){
        $res = M("user_role as ur ")
          ->join("left join wp_admin_user as au on ur.user_id = au.id")
          ->join("left join wp_role as r on ur.role_id = r.id")
           ->field("au.id as id ,au.username as username ,r.rolename as rolename")
            ->select();
        if(false !== $res){
            return $res;
        }
    }
    
    public function Find($id){
        $res = M("admin_user")
            ->where("id='$id'")    
            ->find(); 
        if(false !== $res){
            return $res;
        }
    }
    
    public function rolefind($id){
        $res = M("user_role as ur")
             ->join("left join wp_role as r on r.id = ur.role_id")   
            ->where("ur.user_id='$id'")    
            ->find(); 
        if(false !== $res){
            return $res;
        }
    }    

    public function userAdd($data){
         return $this->add($data);
    }
    
    public function userroleAdd($data_role){
        return M("user_role")->add($data_role);
    }
    public function deleteList($id){
        if(!$id)return;
       ;
        M("user_role")->where("user_id='$id'")->delete();
        return $this->delete($id);
    }    
    
}